layui.use(['jquery','layer','table','laydate'],function(){
    var $=layui.jquery;
    var layer=layui.layer;
    var table=layui.table;
    var laydate = layui.laydate;

    //绑定时间格式
    laydate.render({
        //绑定元素
        elem: '#updateDate',
        //日期和时间类型
        type: 'datetime',
        //时间事件为点击事件
        trigger: 'click'
    })

    getTable();
    //筛选搜索
    $('#search').on('click',function () {
        var productCode = $('input[name=productCode]').val();
        var productName = $('input[name=productName]').val();
        var updateDate = $('input[name=updateDate]').val();
        getTable(productCode,productName,updateDate);
        $('input[name=productCode]').val('');
        $('input[name=productName]').val('');
    })
    //获取表格数据
    function getTable(productCode,productName,updateDate){
        $.ajax({
            url: '/product/getProductPriceLog',
            type: 'post',
            dataType: 'json',
            data: {'courseId':productCode,'courseName':productName,'updateDate':updateDate,'type':1},
            success: function (data) {
                demoTable(data.data);
            }
        })
    }
    /*表格*/
    function demoTable(data){
        table.render({
            elem:'#demoTable',
            title:"历史价格详情",
            data:data,
            toolbar:'#tableHeader',
            limit:10,
            page:{
                layout:['count','prev','page','next','limit','skip','refresh'],
                limits:[5,10,20],
                first:'首页',
                last:'尾页',
            },
            cols:[[
                {type:'checkbox'},
                {title:'序号',align:'center',templet:function(data){
                        return data.LAY_INDEX;
                    }},
                {field:'courseId',title:'商品编号',align:'center'},
                {field:'courseName',title:'商品名称',align:'center'},
                {field:'coursePrice',title:'原价',align:'center'},
                {field:'courseNprice',title:'现价',align:'center'},
                {field:'updateDate',title:'操作时间',align:'center'},
            ]]
        })
    }
    //刷新
    $('#refresh').click(function () {
        location.reload();
    })
    //返回
    $('#goBack').click(function () {
        parent.tabParentChange(3);
    })
    $(document).click(function () {
        parent.$('.rightMenu').hide();
    });
})